package com.soccernews.main;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;






import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.util.Xml;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class Table extends Activity {
	ListView list;
	private List<Message> messages;
	ProgressDialog pd;
	private Object data = null;
	Elements content;
	Bitmap bitmap;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loading_screen_majidi);
        //this.pd = ProgressDialog.show(this, "Working..", "Downloading Data...", true, false);

    	
        new DownloadTask().execute();
        
    }
    
    private class DownloadTask extends AsyncTask<String, Void, Object> {
        protected Object doInBackground(String... args) {
            Log.i("MyApp", "Background thread starting");
            try {
            Document doc = Jsoup.connect("http://www.varzesh3.com/").get();
            
			
			
			 content = doc.select("div#widget-place-2");
			 content = content.select("div#identifierwidget-1");
			 content = content.select("div.widget-content");
            
		    
		     
		     
		    
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
            return content;
        }

        protected void onPostExecute(Object result) {
            // Pass the result data back to the main activity
        	Table.this.data = result;
        	if (content == null)
        		new DownloadTask().execute();
        	else{
        	setContentView(R.layout.table);
        	//TextView test = (TextView)findViewById(R.id.textView1);
        	WebView myWebView = (WebView) findViewById(R.id.tableView);
        	WebSettings webSettings = myWebView.getSettings();
        	webSettings.setJavaScriptEnabled(true);
        	
        	myWebView.addJavascriptInterface(new Object(), "injectedObject");
        	
        	String header = "<html xmlns='http://www.w3.org/1999/xhtml'>" +
        			"<head profile='http://gmpg.org/xfn/11'><META http-equiv='Content-Type' " +
        			"content='text/html; charset=utf-8'> <link rel=\"stylesheet\" type=\"text/css\"  href=\"http://www3.varzesh3.com/football3_styles/varzesh3-v6.css\" />" +
        			"<script src=\"http://www3.varzesh3.com/football3_jscripts/javascripts-v3.js\" type=\"text/javascript\"></script>"+
        			"</head><body style=\"background-color: #ADD8E6;\">"+
        			"<div style=\"margin:20px;\">";
        	
				myWebView.loadDataWithBaseURL("http://www.varzesh3.com/",header+
						content.html()+"</html></body>" , "text/html", "UTF-8", null);
			
				myWebView.setBackgroundColor(R.color.Cyan);
   		}	
        	if (Table.this.pd != null) {
            	Table.this.pd.dismiss();
            }
        }
    }
      

        
       
        
        	
    
    

	
}